package io.renren.common.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Swagger配置
 *
 * @author Mark sunlightcs@gmail.com
 */
@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI createRestApi() {
        return new OpenAPI()
                .info(apiInfo())
                //.addSecurityItem(new SecurityRequirement().addList(Constant.TOKEN_HEADER))
                //.components(new Components().addSecuritySchemes(Constant.TOKEN_HEADER, new SecurityScheme()
                //        .name(Constant.TOKEN_HEADER).in(SecurityScheme.In.HEADER).type(SecurityScheme.Type.HTTP)))
                ;
    }

    //@Bean
    //public GlobalOpenApiCustomizer orderGlobalOpenApiCustomizer() {
    //    return openApi -> {
    //        // 全局添加鉴权参数
    //        if (openApi.getPaths() != null) {
    //            openApi.getPaths().forEach((s, pathItem) -> {
    //                // 为所有接口添加鉴权
    //                pathItem.readOperations().forEach(operation -> {
    //                    operation.addSecurityItem(new SecurityRequirement().addList(Constant.TOKEN_HEADER));
    //                });
    //            });
    //        }
    //
    //    };
    //}

    private Info apiInfo() {
        return new Info()
                .title("人人开源")
                .description("renren-admin文档")
                .version("5.x");
    }
}
